package com.example.wechat2

import android.content.ContentValues
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wechat.ChatAdapter
import kotlinx.android.synthetic.main.fragment_chat.*


class ChatFragment : Fragment() {

    val TAG = "@@ChatFragment"

    val chatInfos = arrayListOf<ChatInfo>()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        Log.d(TAG,"onCreateView")

        return inflater.inflate(R.layout.fragment_chat, container, false)

    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Log.d(TAG,"onViewCreated")

        initData()
        recycler_chat.adapter = ChatAdapter(chatInfos)
        recycler_chat.layoutManager = LinearLayoutManager(MainActivity())

        Log.d(TAG,"sizeofinfo:${chatInfos.size}")

    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        Log.d(TAG,"onAttach")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG,"onCreate")

    }



    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        Log.d(TAG,"onActivityCreated")
    }



    override fun onStart() {
        super.onStart()
        Log.d(TAG,"onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG,"onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG,"onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG,"onStop")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.d(TAG,"onDestroyView")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG,"onDestroy")
    }

    override fun onDetach() {
        super.onDetach()
        Log.d(TAG,"onDetach")
    }

    private fun initData() {
        Log.d(ContentValues.TAG,"initdata")
        for(i in 0..3) {
            chatInfos.add(ChatInfo().apply {
                chatinfo_name = "木子李"
                chatinfo_time = "23:22"
                chatinfo_msg = "哈哈哈哈哈哈哈哈哈哈哈吼吼吼吼吼吼吼"
                chatinfo_headimg = R.mipmap.head4
            })
            chatInfos.add(ChatInfo().apply {
                chatinfo_name = "CandyTang"
                chatinfo_time = "23:12"
                chatinfo_msg = "太好笑了哈哈哈哈吼吼吼吼吼吼吼"
                chatinfo_headimg = R.mipmap.head2
            })
            chatInfos.add(ChatInfo().apply {
                chatinfo_name = "LuoRainStar"
                chatinfo_time = "22:42"
                chatinfo_msg = "姐就是女王 自信放光芒！"
                chatinfo_headimg = R.mipmap.head3
            })
            chatInfos.add(ChatInfo().apply {
                chatinfo_name = "乐乐"
                chatinfo_time = "22:33"
                chatinfo_msg = "好的好的"
                chatinfo_headimg = R.mipmap.head5
            })
        }

    }

}